package cn.kaguyaever.dao.impl;

import cn.kaguyaever.dao.UserDao;
import cn.kaguyaever.entity.User;

public class UserDaoImpl extends BaseDao<User> implements UserDao {
    public User queryUserByUsername(String username) {
        String sql = "select `id`,`username`,`password`,`email` from user where username = ?";
        return queryForOne(sql,username);
    }

    public User queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select `id`,`username`,`password`,`email` from user where username = ? and password = ?";
        return queryForOne(sql,username,password);
    }

    public int saveUser(User user) {
        String sql = "insert into user(`username`,`password`,`email`) values(?,?,?)";
        return update(sql,user.getUsername(),user.getPassword(),user.getEmail());
    }

    public int changePassword(String password,Integer id){
        String sql = "update user set password = ? where id = ?";
        return update(sql,password,id);
    }
}
